package com.gxa.adput.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.adput.mapper.ReportManagementMapper;
import com.gxa.adput.service.ReportManagementService;
import com.gxa.common.R;
import com.gxa.common.entity.platform_maintenance_service1001.ReportManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ReportManagementServiceIimpl extends ServiceImpl<ReportManagementMapper, ReportManagement> implements ReportManagementService {

    @Autowired
    private ReportManagementMapper reportManagementMapper;

    @Override
    public R ReportManagementByPage(Integer currentPage, Integer pageSize) {

        R r = new R();
        QueryWrapper<ReportManagement> queryWrapper = new QueryWrapper<>();
        Page<ReportManagement> page = new Page<>(currentPage,pageSize);
        Page<ReportManagement> reportManagementPage = reportManagementMapper.selectPage(page, queryWrapper);
        r.setMessage("按照分页查询成功");
        r.setCode(200);
        r.setData(reportManagementPage);

        return r;
    }

    @Override
    public R ReportManagementCondition(ReportManagement reportManagement) {
       List<ReportManagement> reportManagementList =  reportManagementMapper.ReportManagementCondition(reportManagement);
        R r = new R();
        r.setCode(200);
        r.setMessage("按照条件查询成功");
        r.setData(reportManagementList);
        return r;
    }

    @Override
    public R updateReportManagementByStatus(ReportManagement reportManagement) {
        R r = new R();
        ReportManagement selectById = reportManagementMapper.selectById(reportManagement.getId());
        if(selectById.getStatus() == 0){
            r.setMessage("不用做处理");
        }else if(selectById.getStatus() == 1){
            selectById.setStatus(0);
            r.setCode(200);
            r.setMessage("处理成功");
            r.setData(selectById);
        }


        return r;
    }

    @Override
    public R selectReportAll() {
        R r = new R();
        List<ReportManagement> reportManagements = reportManagementMapper.selectList(null);
        r.setCode(200);
        r.setMessage("查询全部成功");
        r.setData(reportManagements);

        return r;
    }
}
